package vy.org.app.page.satsang;

/**
 * @author Ravi Shankar
 *
 */

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.vy.dal.dao.VySatsangDAO;
import org.vy.dal.dao.VySatsangDO;

import vy.org.app.common.AppConstants;
import vy.org.app.common.BaseAction;
import vy.org.app.common.ModeEnum;
import vy.org.app.common.ModuleEnum;

public class MntnSatsangAction extends BaseAction {

	@Override
	public ActionForward executeAction(ActionMapping mapping,
			ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) {

		MntnSatsangForm form = (MntnSatsangForm) actionForm;
		VySatsangDO dto = new VySatsangDO();
		if (form != null && form.getMode() != null) {
			if (ModeEnum.SEARCH.getName().equals(form.getMode())) {
				dto = MntnSatsangAssembler.getAssembler().getSatsangDO(form);
				try {
					request.setAttribute(AppConstants.RESULT, VySatsangDAO
							.findByParam(dto));
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else if (ModeEnum.ADD.getName().equals(form.getMode())) {
				dto = MntnSatsangAssembler.getAssembler().getSatsangDO(form);
				try {
					VySatsangDAO.insert(dto);
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else if (ModeEnum.DELETE.getName().equals(form.getMode())) {
				dto = MntnSatsangAssembler.getAssembler().getSatsangDO(form);
				try {
					VySatsangDAO.delete(dto.getSatsangId());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return mapping.findForward("success");
	}

	@Override
	protected ModuleEnum getModuleId() {
		return ModuleEnum.ADD_SATSANG;
	}

}
